// 给定一个正整数数组nums和整数k，找出该数组内乘积小于k的连续的子数组的个数
// 思路，滑动窗口
// left和right分别指向滑动窗口的左右边界，维护滑动窗口中元素的乘积小于k

function numSubarrayProductLessThanK(arr, k) {
    if (k <= 1) {
        return 0
    }
    let left = 0
    let right = 0
    let window_product = 1
    let res = 0
    while (right < arr.length) {
        window_product *= arr[right]
        while (window_product >= k) {
            window_product /= arr[left]
            left++
        }
        // 仅统计右指针的左指针范围是因为其他子数组已经在前面计算过了
        res += right - left + 1
        right++
    }
    return res
}

let arr = [10, 5, 2, 6]
let k = 100
console.log(numSubarrayProductLessThanK(arr, k));